package com.ruoyi.equ.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equ.domain.EquColRetuRecording;
import com.ruoyi.equ.service.IEquBasicService;
import com.ruoyi.equ.service.IEquColRetuRecordingService;
import com.ruoyi.equ.service.IEquCollectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备出入库记录信息Controller
 * 
 * @author luguanqing
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/equ/recording")
public class EquColRetuRecordingController extends BaseController
{
    @Autowired
    private IEquColRetuRecordingService equColRetuRecordingService;

    @Autowired
    private IEquCollectService equCollectService;

    @Autowired
    private IEquBasicService equBasicService;



    /**
     * 查询设备出入库记录信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EquColRetuRecording equColRetuRecording)
    {
        startPage();
        List<EquColRetuRecording> list = equColRetuRecordingService.selectEquColRetuRecordingList(equColRetuRecording);
        return getDataTable(list);
    }


    /**
     * 导出设备出入库记录信息列表
     */
    @Log(title = "设备出入库记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value="设备出入库记录信息")
    public void export(HttpServletResponse response, EquColRetuRecording equColRetuRecording)
    {
        List<EquColRetuRecording> list = equColRetuRecordingService.selectEquColRetuRecordingList(equColRetuRecording);
        ExcelUtil<EquColRetuRecording> util = new ExcelUtil<EquColRetuRecording>(EquColRetuRecording.class);
        util.exportExcel(response, list, "设备出入库");
    }

    /**
     * 获取设备出入库记录信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(equColRetuRecordingService.selectEquColRetuRecordingById(id));
    }

    /**
     * 获取设备领用信息
     */
    @GetMapping(value = "/getColByNum/{equNum}")
    public AjaxResult getColByNum(@PathVariable("equNum") String equNum){
        return AjaxResult.success(equColRetuRecordingService.selectEquColRetuRecordingByEquNum(equNum));
    }

    /**
     * 新增设备出入库记录信息
     */
    @Log(title = "设备出入库记录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquColRetuRecording equColRetuRecording)
    {
        return toAjax(equColRetuRecordingService.insertEquColRetuRecording(equColRetuRecording));
    }

    /**
     * 修改设备出入库记录信息
     */
    @Log(title = "设备出入库记录信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquColRetuRecording equColRetuRecording)
    {
        return toAjax(equColRetuRecordingService.updateEquColRetuRecording(equColRetuRecording));
    }



    /**
     * 删除设备出入库记录信息
     */
    @Log(title = "设备出入库记录信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(equColRetuRecordingService.deleteEquColRetuRecordingByIds(ids));
    }
}
